﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace ezyGoezy
{
    public partial class Form1 : Form
    {
        int currhrs, currmin, currsec;

        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(char.IsDigit(e.KeyChar))&& (e.KeyChar!=8))
            {
                e.Handled = true;
                textBox5.Text = "Please enter an integer only";
            }
            else
                textBox5.Text = "";
        }

        private void okbutton_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                textBox5.Text = "Please enter a commuter ID";
                return;
            }
            if (comboBox1.Text == "")
            {
                textBox5.Text = "Please enter a value in the Start Time Hrs field";
                return;
            }
            if (comboBox2.Text == "")
            {
                textBox5.Text = "Please enter a value in the Start Time Min field";
                return;
            }
            if (comboBox3.Text == "")
            {
                textBox5.Text = "Please enter a value in the Start Time Sec field";
                return;
            }
            if (comboBox4.Text == "")
            {
                textBox5.Text = "Please enter a value in the End Time Hrs field";
                return;
            }
            if (comboBox5.Text == "")
            {
                textBox5.Text = "Please enter a value in the End Time Min field";
                return;
            }
            if (comboBox6.Text == "")
            {
                textBox5.Text = "Please enter a value in the End Time Sec field";
                return;
            }

            int commuterid = Convert.ToInt32(textBox1.Text);

            int starttimehrs = Convert.ToInt16(comboBox1.Text);
            int starttimemin = Convert.ToInt16(comboBox2.Text);
            int starttimesec = Convert.ToInt16(comboBox3.Text);
            int endtimehrs = Convert.ToInt16(comboBox4.Text);
            int endtimemin = Convert.ToInt16(comboBox5.Text);
            int endtimesec = Convert.ToInt16(comboBox6.Text);

            if (starttimehrs > endtimehrs)
            {
                textBox5.Text = "Start time cannot be greater than end time";
                return;
            }
            else if (starttimehrs==endtimehrs)
            {
                if (starttimemin > endtimemin)
                {
                    textBox5.Text = "Start time cannot be greater than end time";
                    return;
                }
                else if (starttimemin == endtimemin)
                    if (starttimesec >= endtimesec)
                    {
                        textBox5.Text = "Start time cannot be greater than or equal to end time";
                        return;
                    }
            }

            if (currhrs > starttimehrs)
            {
                textBox5.Text = "Current time cannot be greater than start time";
                return;
            }
            else if (currhrs == starttimehrs)
            {
                if (currmin > starttimemin)
                {
                    textBox5.Text = "Current time cannot be greater than start time";
                    return;
                }
                else if (currmin == starttimemin)
                    if (currsec >= starttimesec)
                    {
                        textBox5.Text = "Current time cannot be greater than or equal to start time";
                        return;
                    }
            }

            textBox5.Text = "Trip successfully added";
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            DateTime CurrTime = DateTime.Now;
            currhrs = CurrTime.Hour;
            currmin = CurrTime.Minute;
            currsec = CurrTime.Second;
            textBox2.Text = (CurrTime.Hour + ":" + CurrTime.Minute + ":" + CurrTime.Second);
        }

        private void Form1_Click(object sender, EventArgs e)
        {
            textBox5.Text = "";
        }



    }
}
